using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;

public class GameMgr : MonoBehaviour
{
    private LuaEnv lua = new LuaEnv();//构建lua虚拟机

    Action action_Satrt, action_update;
    // Start is called before the first frame update
    void Start()
    {
        lua.AddLoader(CustomerLoder);
        lua.DoString(chunk:"require'luaMain'");
        string path= lua.Global.GetInPath<string>("str");
        Debug.Log(path);
        Action action= lua.Global.GetInPath<Action>("printname");
        action_Satrt = lua.Global.GetInPath<Action>("LauStart");
        action_update = lua.Global.GetInPath<Action>("LuaUpDate");

        if(action_Satrt != null )
        {
            action_Satrt();
        }
        action();
    }

    private byte[] CustomerLoder(ref string filepath)
    {
        string path = Application.dataPath + "/LuaScript/" + filepath + ".lua";
        return File.ReadAllBytes(path);
    }

    // Update is called once per frame
    void Update()
    {
        if (action_update != null)
        {
            action_update();
        }
    }
}
